<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>购物车页面</title>
	<link rel="stylesheet" href="./Public/Home/style/css/cart.css">
	<link rel="stylesheet" href="./Public/Home/style/css/font.css">
	<script type="text/javascript" src="./Public/Home/style/js/jquery-3.0.0.min.js"></script>
</head>
<body>
	<!-- 头部 -->
	<div id="top">
		<div id="top1">
			<div class="top1_l">
				<i class="iconfont" style="color:#919290;">&#xe602;</i>
				<span>美丽说首页</span>
			</div>
			<ul class="top1_r">
			<?php if(isset($_SESSION['username'])):?> 
				<li class="top1_rl" style="width:58px;">
					<a href="">{{$_SESSION['username']}}</a>
					<div class="top1_rlh">
						<ul>
							<li>
								<a href="">个人设置</a>
							</li>
							<li>
								<a href="">退出</a>
							</li>
						</ul>
					</div>
				</li>
			<?php else: ?>
				<li class="top1_rl" style="width:50px;">
					<div class="top1_rl1d">
						<a href="{{U('Member/login')}}">
							登录
						</a>
					</div>
				</li>
				<li class="top1_rl" style="width:50px;">
					<div class="top1_rl1d">
						<a href="{{U('Member/reg')}}">
							注册
						</a>
					</div>
				</li>
			<?php endif?>
				<li class="top1_rl1" style="width:80px;">
					<div class="top1_rl1d">
						<a href="">我的收藏</a>
					</div>
				</li>
				<li class="top1_rl1" style="width:100px;">
					<div class="top1_rl1d">
						<a href="formlist.html">
							<i class="iconfont" style="color:#919290;">&#xe601;</i>
							我的订单
						</a>
					</div>
				</li>
				<li class="top1_rl1" style="width:100px;">
					<div class="top1_rl1d">
						<a href="">
							<i class="iconfont" style="color:#919290;">&#xe602;</i>
							购物车
						</a>
					</div>
					<div class="top1_rlh1">
						<ul>
							<li>
								<img src="./Public/Home/style/images/mls21.jpg" alt="">
								<div class="top1_rlh1c">
									<a href="">MECITY女T恤短袖圆领字母</a>
									<span>颜色: 亮白色 尺码:S</span>
								</div>
								<div class="top1_rlh1b">
									<span>¥49</span>
									<span>删除</span>
								</div>
							</li>
							<li>
								<img src="./Public/Home/style/images/mls21.jpg" alt="">
								<div class="top1_rlh1c">
									<a href="">MECITY女T恤短袖圆领字母</a>
									<span>颜色: 亮白色 尺码:S</span>
								</div>
								<div class="top1_rlh1b">
									<span>¥49</span>
									<span>删除</span>
								</div>
							</li>
							<li class="top1_rlh1l">
								<div class="top1_rlh1d">
									<a href="">查看购物车</a>
								</div>
							</li>
						</ul>
					</div>
				</li>
				<li class="top1_rl1" style="width:100px;">
					<div class="top1_rl1d">
						<a href="">
							<i class="iconfont" style="color:#919290;">&#xe602;</i>
							我的订单
						</a>
					</div>
				</li>
				
			</ul>
		</div>
	</div>

	<!-- banner区域 -->
		<div id="banner">
			<div id="banner0">
				<div id="banner1">
					<div id="banner1_l">
						<img src="./Public/Home/style/images/mls9.png" alt="">
					</div>
					<div id="banner1_r">
						<div id="banner1_r1"></div>
					</div>
				</div>
			</div>
		
	<!-- ；列表区域 -->
		<div id="menu">
			<ul >
				<li class="menu1" style="background:#999;border-radius:5%;">
					<a href="" >全部商品（{{count($data['cart']['goods'])}}）</a>
				</li>
				
			</ul>
		</div>
		
				<!-- 选购商品 -->
			<div id="opt">
				<div id="opt_t">
					<div class="opt_tr">
						<div class="opt_td">
							<div class="opt_td1">
								<input type="checkbox" class="qx">
								<span>全选</span>
							</div>
							<div class="opt_td2">
								<span>商品</span>
							</div>
							<div class="opt_td3">
								<span>商品信息</span>
							</div>
							<div class="opt_td4">
								<span>单价(元)</span>
							</div>
							<div class="opt_td5">
								<span>数量</span>
							</div>
							<div class="opt_td6">
								<span>小计(元)</span>
							</div>
							<div class="opt_td7">
								<span>操作</span>
							</div>
						</div>
					</div>
					<?php if(count($data['cart']['goods'])==null) {?>
						<div style="width:1200px;height:200px;margin:0 auto; text-align:center;color:#f69;font-size:40px;line-height:200px;background:white;">购物车没有商品，请前去添加
						<a href="{{U('Index/index')}}">
							进入主页浏览
						</a>
						</div>
					<?php }?>
					<div class="opt_tr2">
					{{foreach from="$data['cart']['goods']"  key='$k' value='$v'}}
						<div class="opt_td">
							<div class="opt_td1">
								<input type="checkbox">
								<span>选择</span>
							</div>
							<div class="opt_td2">
								<img src="{{$v['options']['pic']}}" alt="">
								<a href="{{U('Shop/index',['gid'=>$v['id']])}}">{{$v['name']}}</a>
							</div>
							<div class="opt_td3">
							{{foreach from="$v['options']['name']" value="$value"}}
								<div class="opt_td31" style="height:30px;">{{$value['name']}}：{{$value['value']}}</div>
							{{endforeach}}
							</div>
							<div class="opt_td4">
								<span>{{$v['price']}}</span>
							</div>
							<div class="opt_td5">

								<div class="opt_td51">
								<span>-</span>
								</div>

								<div class="opt_td52">{{$v['num']}}</div>
								<div class="opt_td53">+</div>
							</div>
							<div class="opt_td6">
								<span>{{$v['total']}}</span>
							</div>
							<div class="opt_td7">
								<a href="{{U('Cart/index',array('d'=>$k))}}"><span>删除</span></a>
							</div>
						</div>
						{{endforeach}}
				
					</div>

					<div class="opt_tr3">
						<div class="opt_tr31">
							<input type="checkbox" class="qx">
							
						</div>
						<div class="opt_tr32">
							<span>全选</span>
							<a href="">删除</a>
						</div>
						<div class="opt_tr33">
							<div class="opt_tr33d">
								<span>共有 <span>{{$data['cart']['total_rows']}} </span>件商品，总计:</span>
							</div>
							<div class="opt_tr33d1">
								<span>￥{{$data['cart']['total']}}</span>
							</div>
							<div class="opt_tr33d2">
								<a href="{{U('Form/index')}}" style=" text-decoration: none;color:white;"><span>去付款></span></a>
							</div>
						</div>
							
					</div>
				</div>
			</div>
			
		
			<!-- 站点配置 -->
		<div id="web" style="background:#FBFBFB;border-top:1px solid #ccc;margin-top:20px;">
			<span>Copyright ©2016 Meilishuo.com</span>
			<a href=""> 电信与信息服务业务经营许可证100798号</a>
			<a href="">经营性网站备案信息</a>
			<span>京ICP备11031139号</span>
			<span>京公网安备110108006045</span>
		</div>
	</div>
	<!-- 还有刚才这个地方脚本不要放在循环里面  我移下来了 -->
	<script>
		$(function(){
			var oo=$(this).index();
			$('.opt_td51').click(function(){
				//刚才你 这个地方 opt_td52 前面少点了
				var num=parseInt($(this).siblings('.opt_td52').html());
				
				num=num-1;
				num=num<1 ? 1:num;
				$(this).siblings('.opt_td52').html(num);
				//计算总价
				var danjia = $(this).parent().siblings('.opt_td4');
				//parseInt(danjia.text());
				var zongjia = $(this).parent().siblings('.opt_td6');
				//parseInt(zongjia.text());
				//console.log(parseFloat(danjia.text())*num);
				var myfloat=parseFloat(danjia.text())*num;
				zongjia.find('span').text(myfloat.toFixed(2));

				//console.log();


				})
			$('.opt_td53').click(function(){
					var num=parseInt($(this).siblings('.opt_td52').html())||0;
					num=num+1;
					$(this).siblings('.opt_td52').html(num);
					var danjia=$(this).parent().siblings('.opt_td4');
					var zongjia = $(this).parent().siblings('.opt_td6');
					var myfloat=parseFloat(danjia.text())*num;
					zongjia.find('span').text(myfloat.toFixed(2));
			})
			function jjjj(){
				var obj = $("#opt_t input[type=checkbox]:checked").not('.qx');
				var mymoney=0.00;

				$.each(obj,function(k,v){
					//console.log(v);
					var strmoney = $(this).parent().siblings('.opt_td6').text();
					console.log(strmoney,parseFloat(strmoney));
					mymoney+=parseFloat(strmoney);
				});
				console.log(mymoney.toFixed(2));
				//商品数量
				$('.opt_tr33d span span').text(obj.length);
				//总价
				$('.opt_tr33d1 span').text('￥'+mymoney.toFixed(2));
				// console.log(mymoney);
				if(mymoney>0){
					// alert(1);
					$('.opt_tr33d2').css({background:"red"});
				}else{
					$('.opt_tr33d2').css({background:"#ccc"});
				}

			}
			//选中
			$("#opt_t input[type=checkbox]").not('.qx').click(function(){
				jjjj();

			});
			//全选
			$("#opt_t input[type=checkbox].qx").click(function(){
				var state = $(this)[0].checked;
				//console.log($(this));
				$("#opt_t input[type=checkbox]").prop('checked',state);
				//$("#opt_t input[type=checkbox]").not('.qx').click();
				jjjj();
			});

			
		})
	</script>
</body>
</html>